/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.hibernate.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "CATEGORY_INFO")
public class CategoryInfo extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "CategoryInfo";
	public static final String ALIAS_CATEGORY_ID = "Id";
	public static final String ALIAS_CATEGORY_NAME = "categoryName";
	public static final String ALIAS_PID = "pid";
	public static final String ALIAS_RAW_DATA = "rawData";
	public static final String ALIAS_IS_PARENT = "isParent";
	public static final String ALIAS_REMARK = "remark";
	public static final String ALIAS_IS_DELETE = "isDelete";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long categoryId;
	@NotBlank @Length(max=100)
	private java.lang.String categoryName;
	
	private Long pid;
	@NotBlank @Length(max=500)
	private java.lang.String rawData;
	@NotBlank @Length(max=1)
	private java.lang.String isParent;
	@Length(max=500)
	private java.lang.String remark;
	@NotBlank @Length(max=1)
	private java.lang.String isDelete;
	//columns END


	public CategoryInfo(){
	}

	public CategoryInfo(
		Long categoryId
	){
		this.categoryId = categoryId;
	}

	

	public void setCategoryId(Long value) {
		this.categoryId = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "CATEGORY_ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getCategoryId() {
		return this.categoryId;
	}
	
	@Column(name = "CATEGORY_NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getCategoryName() {
		return this.categoryName;
	}
	
	public void setCategoryName(java.lang.String value) {
		this.categoryName = value;
	}
	
	@Column(name = "P_ID", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public Long getPid() {
		return this.pid;
	}
	
	public void setPid(Long value) {
		this.pid = value;
	}
	
	@Column(name = "RAW_DATA", unique = false, nullable = false, insertable = true, updatable = true, length = 500)
	public java.lang.String getRawData() {
		return this.rawData;
	}
	
	public void setRawData(java.lang.String value) {
		this.rawData = value;
	}
	
	@Column(name = "IS_PARENT", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getIsParent() {
		return this.isParent;
	}
	
	public void setIsParent(java.lang.String value) {
		this.isParent = value;
	}
	
	@Column(name = "REMARK", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
	public java.lang.String getRemark() {
		return this.remark;
	}
	
	public void setRemark(java.lang.String value) {
		this.remark = value;
	}
	
	@Column(name = "IS_DELETE", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getIsDelete() {
		return this.isDelete;
	}
	
	public void setIsDelete(java.lang.String value) {
		this.isDelete = value;
	}
	
	
	private List categoryInfos = new ArrayList(0);
	public void setCategoryInfos(List<CategoryInfo> categoryInfo){
		this.categoryInfos = categoryInfo;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "categoryInfo")
	public List<CategoryInfo> getCategoryInfos() {
		return categoryInfos;
	}
	
	private CategoryInfo categoryInfo;
	public void setCategoryInfo(CategoryInfo categoryInfo){
		this.categoryInfo = categoryInfo;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "P_ID",nullable = true, insertable = false, updatable = false) 
	})
	public CategoryInfo getCategoryInfo() {
		return categoryInfo;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("CategoryId",getCategoryId())
			.append("CategoryName",getCategoryName())
			.append("Pid",getPid())
			.append("RawData",getRawData())
			.append("IsParent",getIsParent())
			.append("Remark",getRemark())
			.append("IsDelete",getIsDelete())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getCategoryId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof CategoryInfo == false) return false;
		if(this == obj) return true;
		CategoryInfo other = (CategoryInfo)obj;
		return new EqualsBuilder()
			.append(getCategoryId(),other.getCategoryId())
			.isEquals();
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "类目";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getCategoryId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getCategoryName();
	}
}

